package com.db.yupao.config;


import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ProjectName: yupao-back
 * @ClassName: RedissonConfig
 * @Author: LYP
 * @Version: 1.0.0
 * @CreateTime:2025/8/15 16:38
 * @Description: TODO
 */

@Data
@Configuration
@ConfigurationProperties(prefix = "spring.data.redis") // 读取yaml文件中的redisson配置
public class RedissonConfig {


    private String host;
    private String port;
    @Bean
    public RedissonClient redissonClient() {
        // 创建配置
        String redisAddress = "redis://" + host + ":" + port;
        Config config = new Config();
        // 使用Jackson序列化替代默认的FST序列化
        config.setCodec(new JsonJacksonCodec());
        config.useSingleServer()
                .setAddress(redisAddress).setDatabase(0);
        RedissonClient redisson = Redisson.create(config);



//        RedissonReactiveClient redissonReactive = Redisson.createReactive(config);
//
//        RedissonRxClient redissonRx = Redisson.createRx(config);


        return redisson;
    }

}
